from kombu.utils import json
from ronglian_sms_sdk import SmsSDK
from p6_0518 import settings
from p6_0518.celery import app

@app.task
def send_message(sms_code,mobile,expire=5):
    # 实例化工具对象
    sdk = SmsSDK(accId=settings.ACCID, accToken=settings.ACCTOKEN, appId=settings.APPID)
    # 准备数据
    tid = "1"
    datas = ("%s"%sms_code, "%s"%expire)
    # 发送短信
    res = sdk.sendMessage(tid=tid,mobile=mobile,datas=datas)
    print("容联云返回的响应:",res)
    # 解析json数据
    data= json.loads(res)
    # 判断发送短信是否成功
    if data.get("statusCode") == "000000":
        return True
    return False









